<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      box-sizing: border-box;
    }
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      overflow: hidden;
      margin: 0;
      background-image: linear-gradient(to left, #7d5fff,#7158e2);
    }
    .search {
      position: relative;
      height: 50px;
    }
    .search .input {
      transition: width 0.3s ease; 
      background-color: #fff;
      border: 0;
      font-size: 18px;
      padding: 15px;
      height: 50px;
      width: 50px;
    }
    .btn {
      position: absolute;
      top: 0;
      left: 0;
      transition: transform 0.3s ease; 
      cursor: pointer;
      height: 50px;
      width: 50px;
      border: 0;
    }
    .btn:focus, 
    .input:focus {
      outline: none;
    }
    .search.active .input {
      width: 200px;
    }
    .search.active .btn {
      transform: translateX(198px);
    }
  </style>
</head>
<body>
  <div class="search">
    <input class="input" type="text" name="" id="">
    <button class="btn">搜</button>
  </div>

  <script>
    const search = document.querySelector(".search");
    const input = document.querySelector(".input");
    const btn = document.querySelector(".btn");

    btn.addEventListener("click", () => {
      search.classList.toggle("active");
      input.focus();
    })
  </script>
</body>
</html>